package o;

import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Pair;
import java.lang.ref.WeakReference;
import java.lang.reflect.ParameterizedType;
import java.util.concurrent.CountDownLatch;
import o.ffr.e;

public abstract class fgm<R extends fgj, T extends ffc> extends fgc<R> {
    private WeakReference<fgd> ˊ;
    protected ffr ˋ = null;
    private CountDownLatch ˎ;
    private R ॱ = null;

    protected static class c<R extends fgj> extends Handler {
        public c() {
            this(Looper.getMainLooper());
        }

        public c(Looper looper) {
            super(looper);
        }

        public void ˋ(fgl<? super R> o_fgl__super_R, R r) {
            sendMessage(obtainMessage(1, new Pair(o_fgl__super_R, r)));
        }

        public void handleMessage(Message message) {
            switch (message.what) {
                case 1:
                    Pair pair = (Pair) message.obj;
                    ˎ((fgl) pair.first, (fgj) pair.second);
                    return;
                default:
                    return;
            }
        }

        protected void ˎ(fgl<? super R> o_fgl__super_R, R r) {
            o_fgl__super_R.ˊ(r);
        }
    }

    public abstract R ˎ(T t);

    public fgm(fgd o_fgd, String str, ffc o_ffc, Class<T> cls) {
        ˏ(o_fgd, str, o_ffc, cls);
    }

    private void ˏ(fgd o_fgd, String str, ffc o_ffc, Class<T> cls) {
        if (o_fgd == null) {
            throw new IllegalArgumentException("apiClient cannot be null.");
        }
        this.ˊ = new WeakReference(o_fgd);
        this.ˎ = new CountDownLatch(1);
        this.ˋ = new fgk(str, o_ffc, cls);
    }

    public final R ˎ() {
        fgd o_fgd = (fgd) this.ˊ.get();
        if (ॱ(o_fgd)) {
            this.ˋ.ˎ(o_fgd, new e(this) {
                final /* synthetic */ fgm ॱ;

                {
                    this.ॱ = r1;
                }

                public void ˎ(int i, ffc o_ffc) {
                    this.ॱ.ˋ(i, o_ffc);
                    this.ॱ.ˎ.countDown();
                }
            });
            try {
                this.ˎ.await();
            } catch (InterruptedException e) {
                ˋ(207135001, null);
            }
            return this.ॱ;
        }
        ˋ(207135003, null);
        return this.ॱ;
    }

    public final void ˎ(fgl<R> o_fgl_R) {
        ॱ(Looper.getMainLooper(), o_fgl_R);
    }

    public final void ॱ(Looper looper, final fgl<R> o_fgl_R) {
        if (looper == null) {
            looper = Looper.myLooper();
        }
        final c cVar = new c(looper);
        fgd o_fgd = (fgd) this.ˊ.get();
        if (ॱ(o_fgd)) {
            this.ˋ.ˋ(o_fgd, new e(this) {
                final /* synthetic */ fgm ॱ;

                public void ˎ(int i, ffc o_ffc) {
                    this.ॱ.ˋ(i, o_ffc);
                    cVar.ˋ(o_fgl_R, this.ॱ.ॱ);
                }
            });
            return;
        }
        ˋ(207135003, null);
        cVar.ˋ(o_fgl_R, this.ॱ);
    }

    private void ˋ(int i, ffc o_ffc) {
        if (i <= 0) {
            this.ॱ = ˎ(o_ffc);
        } else {
            this.ॱ = ˏ(i);
        }
    }

    protected R ˏ(int i) {
        try {
            this.ॱ = (fgj) fip.ˎ(((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0]).newInstance();
            this.ॱ.ˊ(new fgi(i));
            return this.ॱ;
        } catch (Exception e) {
            return null;
        }
    }

    protected boolean ॱ(fgd o_fgd) {
        return o_fgd != null && o_fgd.ˏ();
    }
}
